#!/bin/sh

# 等待数据库准备就绪
echo "Waiting for MySQL..."
while ! nc -z db 3306; do
    sleep 1
done
echo "MySQL started"

# 等待Redis准备就绪
echo "Waiting for Redis..."
while ! nc -z redis 6379; do
    sleep 1
done
echo "Redis started"

# 运行数据库迁移
echo "Running database migrations..."
alembic upgrade head

# 启动应用
echo "Starting application..."

# 创建数据库表
echo "Creating database tables..."
python create_tables.py

exec uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload 